package com.huiminpay.merchant.controller;

import com.huiminpay.merchant.api.service.AppServiceApi;
import com.huiminpay.merchant.common.util.SecurityUtil;
import com.huiminpay.merchant.api.dto.AppDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(value = "商户平台‐应用管理", tags = "商户平台‐应用相关", description = "商户平台‐应用相关")
@RestController
public class AppController {
    @Reference
    private AppServiceApi appService;

    @ApiOperation("创建商户应用")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "商户应用的参数对象", name = "appDTO", required = true, dataType = "AppDTO", paramType = "body")
    })
    @PostMapping(value = "/my/apps")
    public AppDTO createApp(@RequestBody AppDTO appDTO) {
        Long merchantId = SecurityUtil.getMerchantId();
        appDTO.setMerchantId(merchantId);
        AppDTO app = appService.createApp(appDTO);
        return app;
    }

    @ApiOperation("根据商户Id获取商户应用列表")
    @GetMapping(value = "/my/apps")
    public List<AppDTO> findAppsByMerchantId() {
        Long merchantId = SecurityUtil.getMerchantId();
        List<AppDTO> apps = appService.findAppsByMerchantId(merchantId);
        return apps;
    }

    @ApiOperation("根据appid获取应用的详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", value = "商户应用id", required = true, dataType = "String", paramType = "path")})
    @GetMapping(value = "/my/apps/{appId}")
    public AppDTO findAppById(@PathVariable Long appId) {
        AppDTO appDTO = appService.findAppById(appId);
        return appDTO;
    }


}
